package com.hgc.consumerrabbit.controller;

import com.hgc.consumerrabbit.mapper.consumerMapper;
import com.hgc.consumerrabbit.pojo.User;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 消费者
 */

@Component
@RabbitListener(queues = "QUEUE_DEMO")
public class consumerController1 {

    @Autowired
    private consumerMapper consumerMapper;

    /**
     * @param user
     * @RabbitListener 监听哪个队列(也可以写在类(当前类全部会监听队列)上 写在类上配合 @ RabbitHandler 实现不同消息类型来选择不同的处理方法)
     * @RabbitHandler 根据不同的消息类型来选择不同的处理方法
     * User 消费消息类型
     */
//    @RabbitListener(queues = "QUEUE_DEMO")
    @RabbitHandler
    public void QUEUE_DEMO1(User user) {
        try {
            consumerMapper.insert("QUEUE_DEMO", new Date());
        } catch (Exception e) {
            throw e;
        }

    }
//    @RabbitListener(queues = "QUEUE_DEMO")
    @RabbitHandler
    public void QUEUE_DEMO2(String data) {
        try {
            consumerMapper.insert("QUEUE_DEMO", new Date());
        } catch (Exception e) {
            throw e;
        }

    }
}
